package sel.me.spring.boot159.web.service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.support.TransactionTemplate;
import sel.me.spring.boot159.web.dao.PersonMapper;
import sel.me.spring.boot159.web.entity.PersonDO;

import java.util.List;

/**
 * @author shenenlu 2020年12月25日 下午16:52:44
 */
@Service
public class PersonService {

    @Autowired
    private PersonMapper personMapper;


    @Autowired
    private TransactionTemplate transactionTemplate;


    public void insert(){
        System.out.println("==============" + this.toString());
        PersonDO person = new PersonDO();
//        person.setAge(10);
//        person.setName("andy");
        personMapper.insertSelective(person);
    }


    public PageInfo<PersonDO> selectPage(){
        PageHelper.startPage(2,2);
//        Example example = new Example(PersonDO.class);
        List<PersonDO> personDOS = personMapper.selectAll();
        return new PageInfo<>(personDOS);
    }


    private PageInfo<Object> processPage(PageInfo<PersonDO> pageInfo){
        Page<Object> newPage = new Page<>(pageInfo.getPageNum(),pageInfo.getPages());
        newPage.setTotal(pageInfo.getTotal());
        PageInfo<Object> result = new PageInfo<>(newPage);
//        result.setList(pageInfo.getList());
        return result;
    }

}
